package com.jichangxiu.common.exception;

import com.jichangxiu.common.constant.ErrorCode;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.AuthenticationException;

/**
 * CaptchaException:
 *
 * @author Jcx
 * @create 2023-04-03 21:49
 */
@EqualsAndHashCode(callSuper = true)
public class CaptchaException extends AuthenticationException {

    private static final long serialVersionUID = 1L;

    private String code;

    private String msg;

    public static CaptchaException build() {
        return new CaptchaException(ErrorCode.CAPTCHA_ERROR.getMsg());
    }

    public static CaptchaException build(String msg) {
        return new CaptchaException(msg);
    }

    public static CaptchaException build(String msg, Throwable e) {
        return new CaptchaException(msg, e);
    }

    public CaptchaException(String msg) {
        super(msg);
        this.code = ErrorCode.CAPTCHA_ERROR.getCode();
        this.msg = msg;
    }

    public CaptchaException(ErrorCode errorCode) {
        super(errorCode.getMsg());
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
    }

    public CaptchaException(String msg, Throwable e) {
        super(msg, e);
        this.code = ErrorCode.CAPTCHA_ERROR.getCode();
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
